import React, { useState, useEffect } from 'react';
import store from '../../store';

const useMapState = (fn) => {
  const [data, setData] = useState(null);

  useEffect(() => {
    const unsubscribe = store.subscribe(() => {
      const state = store.getState();
      setData(fn(state));
    });
    return unsubscribe;
  }, []);

  return data;
}

const Product = () => {
  const name = useMapState(state => state.name);
  store.dispatch({ type: 'xxx'  });

  return (
    <></>
  );
}

